<?php

class Addsecurityrelations extends Doctrine_Migration_Base {


    public function createSfGuardPermission($permissionName,$description) {
        $perm = new sfGuardPermission();
        $perm->setName($permissionName);
        $perm->setDescription($description);
        $perm->save(Doctrine_Manager::getInstance()->getCurrentConnection());
    }

    public function up() {
        /**
         * Create the relation type for profiles
         */
        Doctrine_Manager::getInstance()->getCurrentConnection()->beginTransaction();
        $profileRelation = new RelationType();
        $profileRelation->setNameInverse('Security-owner');
        $profileRelation->setTypeName('Security-owner');
        $profileRelation->setTypeValue('security-owner');
        //  $profileRelation->setDisplayGroupBy('security');
        $profileRelation->setValueInverse('security-owner');
        $profileRelation->save(Doctrine_Manager::getInstance()->getCurrentConnection());

       
        Doctrine_Manager::getInstance()->getCurrentConnection()->commit();

        /**
         * Create the permissions
         */
        Doctrine_Manager::getInstance()->getCurrentConnection()->beginTransaction();
        $this->createSfGuardPermission('create-collection', 'Allows users to create collections');
        $this->createSfGuardPermission('restore-any-collection', 'Allows users to restore collections');
        $this->createSfGuardPermission('edit-any-collection', 'Allows users to update any collection');
        $this->createSfGuardPermission('delete-any-collection', 'Allows users to update any collection');

        Doctrine_Manager::getInstance()->getCurrentConnection()->commit();
    }

    public function down() {
    }
}
